package com.bjnangle.nangletool;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by YFB on 2017/8/17.
 */

public class KeyTestActivity extends BaseActivity{
    private TextView tvKeyShow;
    private TextView tvTitle;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_key);
        tvKeyShow = (TextView)findViewById(R.id.key_show);
        setActivity(this);
        ivGoBack = (ImageView)findViewById(R.id.btn_back);
        tvTitle = (TextView)findViewById(R.id.tv_title);
        tvTitle.setText("按键检测");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode){
            case KeyEvent.KEYCODE_1:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"1");
                break;
            case KeyEvent.KEYCODE_2:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"2");
                break;
            case KeyEvent.KEYCODE_3:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"3");
                break;
            case KeyEvent.KEYCODE_4:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"4");
                break;
            case KeyEvent.KEYCODE_5:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"5");
                break;
            case KeyEvent.KEYCODE_6:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"6");
                break;
            case KeyEvent.KEYCODE_7:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"7");
                break;
            case KeyEvent.KEYCODE_8:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"8");
                break;
            case KeyEvent.KEYCODE_9:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"9");
                break;
            case KeyEvent.KEYCODE_0:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"0");
                break;
            case KeyEvent.KEYCODE_STAR:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"*");
                break;
            case KeyEvent.KEYCODE_POUND:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"#");
                break;
            case KeyEvent.KEYCODE_PROG_RED:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"办公广播");
                break;
            case KeyEvent.KEYCODE_PROG_YELLOW:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"病区广播");
                break;
            case KeyEvent.KEYCODE_PROG_GREEN:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"开门");
                break;
            case KeyEvent.KEYCODE_PROG_BLUE:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"接听");
                break;
            case KeyEvent.KEYCODE_VOLUME_UP:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"+");
                break;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"-");
                break;
            case KeyEvent.KEYCODE_TV:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"手柄接听");
                break;
            case KeyEvent.KEYCODE_CALL:
                tvKeyShow.setText(tvKeyShow.getText().toString()+"手柄触发");
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode== KeyEvent.KEYCODE_TV){
            tvKeyShow.setText(tvKeyShow.getText().toString()+"手柄挂断");
        }
        return super.onKeyUp(keyCode, event);

    }
}
